<?php

namespace App\Http\Controllers\Test;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Log;
use Laravel\Pay\PayEase\Facades\PayEase;

/**
 * PayController
 *
 * @package App\Http\Controllers
 * @license [http://www.85do.com] [杭州永奥网络科技有限公司]
 * @copyright Copyright (c) 2018-2026 Hangzhou Yongao Technology Co., Ltd. All rights reserved.
 */
class PayController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return PayController
     */
    public function __construct()
    {

    }

    /**
     * 首页
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        PayEase::configure([], $language = config('app.locale'));

        //$order_no = date('yyyymmdd-82590011-0001-hhmms').substr(microtime(),2,4);
        $date = date('Ymd');
        $time = date('Hms').substr(microtime(), 2, 4);
        $order_no = sprintf('%s-%s-%s-%s', $date, '82590011', '0001', $time);
        //return $order_no;

        $options = [
            'order_no' => $order_no,
            'order_name' => 'order_name',
            'rcv_name' => 'rcv_name',
            'rcv_email' => 'rcv_email',
            'rcv_addr' => 'rcv_addr',
            'rcv_tel' => 'rcv_tel',
            'rcv_post' => 'rcv_post',
            'ymd' => date('Ymd', time()),
            'money' => 0.01,
            'money_type' => 0,
            'return_url' => 'http://cc-demo.weixiaodeyu.com:8090/test/pay/notify'
        ];

        //20090313-888-00001-131019


        $redirect = PayEase::pay($options);

        return $redirect;
    }

    /**
     * Notify
     */
    public function notify(Request $request){
        $options = $request->all();
        $result = PayEase::handleSync($options, function ($result, $status, $data) {
                /**
                 * $result Bool
                 * $status String: <hash failed | pay failed | pending | success>
                 * $data Array
                 */
            dd($data);
                Log::info('notify-result-' . json_encode($result));
                Log::info('notify-status-' . json_encode($status));
                Log::info('notify-data-' . json_encode($data));
            });

        Log::info('notify2-result-' . json_encode($result));
    }
}